// 定时发送邮件
var schedule = require('node-schedule');
var nodemailer = require('nodemailer');
//配置邮件
var transporter = nodemailer.createTransport({
  host: "smtp.163.com",
  secureConnection: true,
  port: 465,
  auth: {
    user: 'chase0010@163.com',
    pass: 'Makaikai19891124',
  }
});
//发送邮件
function sendmail(title, html) {
  var option = {
    from: "chase0010@163.com",
    to: "176196483@qq.com"
  }
  option.subject = title;
  option.html = html;
  transporter.sendMail(option, function(error, response) {
    if (error) {
      console.log("fail: " + error);
    } else {
      console.log("success: " + JSON.stringify(response));
    }
  });
}

function scheduleCronstyle() {
  schedule.scheduleJob('30 * * * * *', function() {
    console.log('scheduleCronstyle:' + new Date());
    //调用发送邮件
    sendmail("Node定时自动发送邮件" + new Date(), "邮件内容：<br/>这是来自nodemailer发送的邮件！");
  });
}

scheduleCronstyle();
